/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * mldivide.c
 *
 * Code generation for function 'mldivide'
 *
 */

/* Include files */
#include "mldivide.h"
#include "rt_nonfinite.h"
#include "xzgetrf.h"
#include <string.h>

/* Function Definitions */
void mldivide(const double A[16], double B[4])
{
  double b_A[16];
  double temp;
  int ipiv[4];
  int b_i;
  int k;
  int kAcol;
  memcpy(&b_A[0], &A[0], 16U * sizeof(double));
  xzgetrf(b_A, ipiv);
  if (ipiv[0] != 1) {
    temp = B[0];
    B[0] = B[ipiv[0] - 1];
    B[ipiv[0] - 1] = temp;
  }
  if (ipiv[1] != 2) {
    temp = B[1];
    B[1] = B[ipiv[1] - 1];
    B[ipiv[1] - 1] = temp;
  }
  if (ipiv[2] != 3) {
    temp = B[2];
    B[2] = B[ipiv[2] - 1];
    B[ipiv[2] - 1] = temp;
  }
  for (k = 0; k < 4; k++) {
    kAcol = k << 2;
    if (B[k] != 0.0) {
      int i;
      i = k + 2;
      for (b_i = i; b_i < 5; b_i++) {
        B[b_i - 1] -= B[k] * b_A[(b_i + kAcol) - 1];
      }
    }
  }
  for (k = 3; k >= 0; k--) {
    kAcol = k << 2;
    temp = B[k];
    if (temp != 0.0) {
      temp /= b_A[k + kAcol];
      B[k] = temp;
      for (b_i = 0; b_i < k; b_i++) {
        B[b_i] -= B[k] * b_A[b_i + kAcol];
      }
    }
  }
}

/* End of code generation (mldivide.c) */
